package com.it.rabbitMQ.test;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * projectName: spring_boot_RabbitQM
 *
 * @author: 王宝贵
 * time: 2024/9/10 19:03 周二
 * description: 消费者
 */
@Component
public class MyMessageListener {

    /**
     * 工作队列模式
     * @param messageContent
     * @param message
     * @param channel
     */

    @RabbitListener(queues = {"atguigu.queue.work"})
    public void processMessage(String messageContent, Message message, Channel channel) {
        System.out.println("messageContent = " + messageContent);
    }


    /**
     * 订阅者模式
     * @param messageContent
     * @param message
     * @param channel
     */
    @RabbitListener(queues = {"com.exchanges.fanout001"})
    public void processMessage01(String messageContent, Message message, Channel channel) {
        System.out.println("Consumer01 Message Content:" + messageContent);
    }

    @RabbitListener(queues = {"com.exchanges.fanout002"})
    public void processMessage02(String messageContent, Message message, Channel channel) {
        System.out.println("Consumer02 Message Content:" + messageContent);
    }


    /**
     * 路由模式
     * @param messageContent
     * @param message
     * @param channel
     */
    @RabbitListener(queues = {"com.exchanges.direct"})
    public void processMessageRouting(String messageContent, Message message, Channel channel) {
        System.out.println("Message Content:" + messageContent);
    }


    /**
     * topic 通配符模式
     * @param messageContent
     * @param message
     * @param channel
     */

    @RabbitListener(queues = {"com.queue.message"})
    public void processMessage04(String messageContent, Message message, Channel channel) {
        System.out.println("Queue Message:" + messageContent);
    }

    @RabbitListener(queues = {"com.queue.order"})
    public void processMessage05(String messageContent, Message message, Channel channel) {
        System.out.println("Queue Order:" + messageContent);
    }


}